package com.ljkj.common.db.dao;

import java.util.List;

import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.ljkj.common.db.basedao.BaseDAO;
import com.ljkj.common.db.domain.ZjfBlessingLanguage;


public class ZjfBlessDAO extends BaseDAO {
	private static final Logger log = LoggerFactory.getLogger(ZjfBlessDAO.class);
	// property constants
	
	@Override
	protected void initDao() {
		// do nothingthis.setSessionFactory(sessionFactory);
	}
	 
	public void save(ZjfBlessingLanguage transientInstance) {
		log.debug("saving ZjfBlessingLanguage instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	 
	public void update(ZjfBlessingLanguage instance) {
		try {
			getHibernateTemplate().update(instance);
			log.debug("update successful");
		} catch (RuntimeException re) {
			log.error("update failed", re);
			throw re;
		}
	}

	public void delete(ZjfBlessingLanguage instance) {
		log.debug("deleting ZjfBlessingLanguage instance");
		try {
			getHibernateTemplate().delete(instance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ZjfBlessingLanguage findById(java.lang.String id) {
		log.debug("getting ZjfBlessingLanguage instance with id: " + id);
		try {
			ZjfBlessingLanguage instance = (ZjfBlessingLanguage) getHibernateTemplate().get(
					"com.ljkj.common.db.domain.ZjfBlessingLanguage", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ZjfBlessingLanguage instance) {
		log.debug("finding ZjfBlessingLanguage instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ZjfBlessingLanguage instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ZjfBlessingLanguage as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findAll() {
		log.debug("finding all ZjfBlessingLanguage instances");
		try {
			String queryString = "from ZjfBlessingLanguage";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ZjfBlessingLanguage merge(ZjfBlessingLanguage detachedInstance) {
		log.debug("merging Tuser instance");
		try {
			ZjfBlessingLanguage result = (ZjfBlessingLanguage) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ZjfBlessingLanguage instance) {
		log.debug("attaching dirty ZjfBlessingLanguage instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ZjfBlessingLanguage instance) {
		log.debug("attaching clean ZjfBlessingLanguage instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ZjfBlessDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ZjfBlessDAO) ctx.getBean("ZjfBlessingLanguageDAO");
	}
}